home *** CD-ROM | disk | FTP | other *** search
- unit QtCopyU;
-
- {$ifdef Ver90} { Delphi 2.0x }
- {$define DelphiLessThan3}
- {$endif}
-
- interface
-
- uses
- SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
-
- type
- TFoo = class
- public
- procedure ShowInfo(const Info: String);
- end;
-
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- end;
-
- var
- Form1: TForm1;
-
- Foo: TFoo;
- TFoo_Create: function (ClassRef: TClass; Construct: Boolean): TFoo;
- TFoo_Destroy: procedure (Handle: TFoo; Destroy: Boolean);
- TFoo_Free: procedure (Handle: TFoo);
- TFoo_ShowInfo: procedure (Handle: TFoo; const Info: String);
-
- implementation
-
- {$R *.DFM}
-
- {$ifdef DelphiLessThan3}
- procedure ShowMessageFmt(const Msg: string; Params: array of const);
- begin
- ShowMessage(Format(Msg, Params));
- end;
- {$endif}
-
- { TFoo }
-
- procedure TFoo.ShowInfo(const Info: String);
- begin
- ShowMessageFmt('%s: %s', [ClassName, Info])
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- Foo: TFoo;
- begin
- Foo := TFoo.Create;
- Foo.ShowInfo('Called through a normal method');
- Foo.Free;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- Foo: TFoo;
- begin
- Foo := TFoo.Create;
- TFoo_ShowInfo(Foo, 'Called through a function pointer');
- Foo.Free;
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- var
- Foo: TFoo;
- begin
- Foo := TFoo_Create(TFoo, True);
- TFoo_ShowInfo(Foo, 'Called through a function pointer');
- //TFoo_Free(Foo);
- TFoo_Destroy(Foo, True)
- end;
-
- initialization
- //Set up procedural variables...
- TFoo_Create := @TFoo.Create;
- TFoo_Free := @TFoo.Free;
- TFoo_Destroy := @TFoo.Destroy;
- TFoo_ShowInfo := @TFoo.ShowInfo;
- end.
-